package com.leyou.web;


import com.leyou.entity.Brand;
import com.leyou.item.dto.BrandDTO;
import com.leyou.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.leyou.dto.PageDTO;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 根据品牌的id集合查询品牌的集合
     * @param brandIds 品牌id的list集合
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<List<BrandDTO>> getBrandsByBrandIds(@RequestParam("ids")List<Long> brandIds ) {
        return ResponseEntity.ok(brandService.getBrandsByBrandIds(brandIds));
    }

    /**
     * 根据分类的id查询品牌
     * @param cid 分类的id
     * @return
     */
    @GetMapping("/of/category")
    public ResponseEntity<List<BrandDTO>> getBrandsByCategoryId(@RequestParam("id")Long cid) {

        return ResponseEntity.ok(brandService.getBrandsByCategoryId(cid));
    }
    @GetMapping("page")
    public ResponseEntity<PageDTO<BrandDTO>> getBrandPage(@RequestParam(value = "key",required = false)String key,
                                                                               @RequestParam(value = "page",defaultValue = "1")String currentPage,
                                                                               @RequestParam(value = "rows",defaultValue = "5")String pageSize
    ) {

        return ResponseEntity.ok(brandService.getBrandPage(key,currentPage,pageSize));

    }

    @GetMapping("{id}")
    public ResponseEntity<BrandDTO> getBrandByBrandId(@PathVariable("id") Long brandId) {
        return ResponseEntity.ok(brandService.getBrandByBrandId(brandId));
    }

//    @PostMapping
//    public ResponseEntity<Void> addBrand(
//            @RequestParam(value = "categoryIds",required = true)List<Long> categoryIds,
//            @RequestParam(value = "letter",required = true)String letter,
//            @RequestParam(value = "name",required = true)String name,
//            @RequestParam(value = "image",required = false)String image,
//            ) {
//
//        return ResponseEntity.ok(brandService.addBrand(categoryIds,letter,name,image));
//
//    }

    /**
     * 新增品牌
     * @param brand
     * @return
     */
    @PostMapping
    public ResponseEntity addBrand(Brand brand) {
        brandService.addBrand(brand);

        return ResponseEntity.status(HttpStatus.CREATED).build();

    }
    /**
     * 更新品牌
     */

    @PutMapping
    public ResponseEntity updateBrand(Brand brand) {
        brandService.updateBrand(brand);

        return ResponseEntity.status(HttpStatus.CREATED).build();

    }










}
